package com.googlecode.loframework.controller
{
	import com.googlecode.loframework.model.ProjectDataProxy;
	import com.googlecode.loframework.view.IComponent;
	import com.googlecode.loframework.view.components.quizzes.IPersonalityQuestion;
	import com.googlecode.loframework.view.components.quizzes.IQuizResults;
	import com.googlecode.loframework.view.components.quizzes.PersonalityQuestionMediator;
	import com.googlecode.loframework.view.components.quizzes.QuizResultsMediator;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.command.SimpleCommand;

	public class QuizItemRegisterMediatorCommand extends SimpleCommand
	{
		public override function execute(notification:INotification):void
		{	
			var component:IComponent = notification.getBody() as IComponent;
			
			if(notification.getBody() as IPersonalityQuestion)
			{
				registerPersonalityQuestion(component);
			}
			
			if(notification.getBody() as IQuizResults)
			{
				registerQuizResults(component);
			}
		}
		
		protected function registerPersonalityQuestion(component:IComponent):void
		{
	
			// register mediator
			var mediator:PersonalityQuestionMediator = new PersonalityQuestionMediator(component);
			facade.registerMediator(mediator);
			
			// add mediator name to model
			project.addComponentMediatorName(mediator.getMediatorName());
		}
		
		protected function registerQuizResults(component:IComponent):void
		{
			// register mediator
			var mediator:QuizResultsMediator = new QuizResultsMediator(component);
			facade.registerMediator(mediator);
			
			// add mediator name to model
			project.addComponentMediatorName(mediator.getMediatorName());
		}
		
		protected function get project():ProjectDataProxy
		{
			var project:IProxy = facade.retrieveProxy(ProjectDataProxy.NAME);
			
			return project as ProjectDataProxy;
		}
	}
}